package com.sqx.modules.toppingConfig.controller;

import com.sqx.common.utils.Result;
import com.sqx.modules.toppingConfig.entity.ToppingConfig;
import com.sqx.modules.toppingConfig.service.IToppingConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 置顶时长配置 前端控制器
 * </p>
 *
 * @author wuchang
 * @since 2023-07-27
 */
@RestController
@RequestMapping("/admin/toppingConfig/")
@Api(value = "时长配置-管理端", tags = {"时长配置-管理端"})
public class AdminToppingConfigController {
    @Autowired
    private IToppingConfigService configService;

    @ApiOperation("新增或修改时长配置")
    @PostMapping("saveConfig")
    public Result saveConfig(ToppingConfig config) {
        return configService.saveConfig(config);
    }

    @ApiOperation("获取时长配置列表")
    @GetMapping("getConfigList")
    public Result getConfigList(Integer page, Integer limit, ToppingConfig config) {
        return Result.success().put("data", configService.getConfigList(page, limit, config));
    }

    @ApiOperation("删除时长配置")
    @PostMapping("deleteConfig")
    public Result deleteConfig(Long configId) {
        return configService.removeById(configId) ? Result.success() : Result.error();
    }
}
